package com.yugao.fintech.draper.generate.controller;

import com.yugao.fintech.draper.core.model.ResultVO;
import com.yugao.fintech.draper.generate.dto.CodeGenPreviewDTO;
import com.yugao.fintech.draper.generate.service.CodeGeneratorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/gen/code")
public class AutoGeneratorController {
    private final CodeGeneratorService codeGeneratorService;

    /**
     * 生成预览代码
     *
     * @param tableName 表名
     * @return 预览代码
     */
    @GetMapping("/codeGenPreview")
    public ResultVO<List<CodeGenPreviewDTO>> codeGenPreview(@RequestParam("tableName") String tableName,
                                                            @RequestParam("dsName") String dsName) {
        return ResultVO.success(codeGeneratorService.codeGenPreview(tableName, dsName));
    }

    /**
     * 生成代码
     *
     * @param tableName 表名
     */
    @GetMapping("/genCodeZip")
    public ResponseEntity<byte[]> genCodeZip(@RequestParam("tableName") String tableName,
                                             @RequestParam("dsName") String dsName) {
        //return codeGeneratorService.genCodeZip(tableName, dsName);
        return null;
    }
}
